package com.dxy.order.controller;

import com.dxy.common.pojo.Order;
import com.dxy.common.vo.Result;
import com.dxy.order.service.OrderService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/createOrder")
    public Result createOrder(String pid, Integer num) {
        if (StringUtils.isBlank(pid)) {
            return Result.fail("商品id不能为空！");
        }
        if (num == null || num <= 0) {
            return Result.fail("商品数量必须大于0！");
        }

        Order order = orderService.createOrder(pid, num);
        return Result.ok(order);
    }
}
